<template>
	<view class="content">
		<view class="index-list">
			<view class="index-item" v-for="item in listData">
				<view class="state-flex">
					<view class="line-text">
						<view :class="item.sbIszx=='1'?'on-line line-box':'out-line line-box'"></view>
						<text><!-- {{item.sbName}} -->{{item.sbClientid}}</text>
					</view>
					<!-- <switch color="#11C88C" style="transform:scale(0.6)" @change="switchChange($event,item)" /> -->
				</view>
				<view class="tie-up" @click="gotoPage('/pages/index/project?name='+item.sbName+'&id='+item.id)">
					<view class="tie-l">
						<image v-if="item.shebeiProjectList.length==0" src="/static/images/icon3.png" mode="widthFix">
						</image>
						<text class="tie-title" v-else>{{item.shebeiProjectList[0].remark}}</text>
						<text>关联项目</text>
					</view>
					<view class="tie-r" v-if="item.shebeiProjectList.length>0">
						<image :src="'/static/images/item'+item.shebeiProjectList[0].projectid+'.png'" mode="widthFix">
						</image>
					</view>
				</view>
			</view>
			<view v-if="noMore" class="no-more">
				<text>没有更多</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listData: [],
				pageNum:1,
				pageSize:14,
				noMore: false
			}
		},
		onLoad() {
			this.getUser()
		},
		onShow() {
			
		},
		onReachBottom() {
		    if (!this.noMore) {
		      this.pageNum++
		      this.getUser()
		    }
		},
		methods: {
			async getUser(){
				let res = await this.http('get','/system/user/getInfo')
				console.log(res)
				if(res.code==200){
					this.getlist(res.user.deptId)
				}
			},
			async getlist(e) {
				let res = await this.http("get", "/tc/shebei/list", {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					sbXxid: e,
					sbClientid: ''
				})
				console.log(res)
				if (res.code == 200) {
					// this.listData = res.rows
					// 数据拼接处理
				    this.listData = [...this.listData, ...res.rows]
				   // 判断是否还有数据
				    this.noMore = res.rows.length < 14
				}
			},
			gotoPage(e){
				uni.navigateTo({
					url: e
				})
			},
			switchChange(event,item){
				const isChecked = event.detail.value;
				console.log(isChecked)
				console.log(item)
			},
		}
	}
</script>

<style lang="less">
	.state-flex{
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 28upx;
		.line-text{
			display: flex;
			align-items: center;
		}
		.line-box{
			width: 8upx;
			height: 8upx;
			border-radius: 50%;
			margin-right: 10upx;
		}
		/deep/ .uni-switch-input:before {
		  background-color: #C7C7C7;
		}
		.on-line{
			background-color: #11C88C;
		}
		.out-line{
			background-color: #EE1314;
		}
	}
	.index-list {
		width: 100%;
		background-color: #fff;
		border-radius: 8upx;
		display: flex;
		flex-wrap: wrap;
	}
	.index-item {
		width: 47%;
		margin: 0 1.5% 20upx 1.5%;
		background-color: #F0F7FA;
		padding: 20upx 0 20upx 20upx;
		box-sizing: border-box;
		border-radius: 10upx;

		.tie-up {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 30upx;

			.tie-l {
				image {
					width: 32upx;
				}

				text {
					font-size: 24upx;
					color: #767676;
					display: block;
				}

				.tie-title {
					font-size: 28upx;
					color: #1A1A1A;
				}
			}

			.tie-r {
				padding-right: 30upx;
				display: flex;
				align-items: center;
				justify-content: center;

				image {
					width: 76upx;
					height: auto;
				}
			}
		}
	}
</style>